package com.china.school.exceptionhandler;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HandlerExceptionResolverTest implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        // 处理异常并返回自定义的错误页面或其他响应
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("errorMessage", "An error occurred: " + ex.getMessage());
        modelAndView.setViewName("error1.html"); // 自定义错误页面的视图名称
        return modelAndView;
    }
}
